﻿#region Using Statements
using System;
using GameBase.Cameras;
using GameBase.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace StarFox.ScreenComponents
{
    /// <summary>
    /// Basic properties needed to implement any 3D content.
    /// </summary>
    public abstract class ScreenComponent3D
    {
        #region Properties

        /// <summary>
        /// Gets the Game that this ScreenComponent3D is associated to.
        /// </summary>
        protected Game Game
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the Screen that this ScreenComponent3D is associated to.
        /// </summary>
        protected Screen Screen
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the GraphicsDevice that this ScreenComponent3D is associated to.
        /// </summary>
        protected GraphicsDevice GraphicsDevice
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the ICamera associated to this ScreenComponent3D.
        /// </summary>
        public ICamera Camera { get; set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="screen">The Screen that this ScreenComponent3D is associated to.</param>
        public ScreenComponent3D(Screen screen)
        {
            Screen = screen;
            Game = Screen.Game;            
            GraphicsDevice = Screen.GraphicsDevice;

            // retrieve a camera from the service list
            Camera = Game.Services.GetService(typeof(ICamera)) as ICamera;
            if (Camera == null)
                throw new InvalidOperationException("Service of type ICamera not found");
        }

        #endregion

        #region Update

        /// <summary>
        /// Called when the ScreenComponent3D needs to be updated.
        /// <para>Override this method with component-specific update code.</para>
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to this method.</param>
        public abstract void Update(GameTime gameTime);

        #endregion

        #region Draw

        /// <summary>
        /// Called when the ScreenComponent3D needs to be drawn.
        /// <para>Override this method with component-specific drawing code.</para>
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to this method.</param>
        public abstract void Draw(GameTime gameTime);

        #endregion
    }
}
